<script setup lang="ts">
const {
  label = '',
  prop,
  iptType,
  iptProps
} = defineProps<{
  label?: string
  prop: BaseModelPropsNameType
  iptType?: IptPropsType['iptType']
  iptProps?: IptPropsType['iptProps']
}>()

const slots = useSlots()

const model = inject<Ref<BaseModelType>>('model', {} as any)
const formItemShow = inject<Ref<BaseModelFormItemShowType | undefined>>('formItemShow')
</script>

<template>
  <template v-if="(formItemShow && formItemShow[prop]) || !formItemShow">
    <x-ipt
      form-item
      :form-item-props="{
        label,
        prop: prop as string
      }"
      :ipt-type="iptType"
      :ipt-props="iptProps"
      :value="model[prop]"
      @update:value="(newVal) => (model[prop] = newVal)"
    >
      <template v-for="(_, name) in slots" #[name]>
        <slot :name="name"></slot>
      </template>
    </x-ipt>
  </template>
</template>

<style scoped lang="scss"></style>
